package com.john.booter.module.file;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.data.repository.query.Param;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.john.booter.config.BooterSettings;
import com.john.booter.module.file.service.FileService;

@RestController
@RequestMapping("/download")
public class DownloadCtrl {
	
	@Autowired
	private BooterSettings setting; 
	@Autowired
	private FileService fileService;

	@RequestMapping(value = "/image", produces = { MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE,
			MediaType.IMAGE_GIF_VALUE })
	public FileSystemResource downloadFile(@Param(value = "id") Long id) {

		String filePath = "E:/temp/booter/bbb.png";
		return new FileSystemResource(new java.io.File(filePath));
	}
	
	@RequestMapping(value = "/image/{uuid}.{suffix}", produces = { MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE,
			MediaType.IMAGE_GIF_VALUE })
	public FileSystemResource downloadImage(@PathVariable(value = "uuid") String uuid, @PathVariable(value = "suffix") String suffix) {
		String filePath = fileService.getPhysicalPath(uuid + "." + suffix);
		return new FileSystemResource(new java.io.File(filePath));
	}

}
